﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
public partial class Admin_News_Info_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   //检查用户权限
        if (Session["Uid"] == null)
        {
            Response.Redirect("AD_Login.aspx");
            return;
        }
        //情况消息框
        lblMessage.Text = "";
        if (!IsPostBack)
        {
            //为GridView绑定数据
            bind();
        }
    }
    /// <summary>
    /// 绑定数据
    /// <remark>2010-10-23 河北大学信管团队-水亚亚 </remark>
    /// </summary>
    private void bind()
    {
        string sql = "select * from News_Info  order by newsTop desc, newsTime desc ";
        GV.DataSource = DataAccess.GetDataSet(sql, null);
        GV.DataKeyNames = new string[] { "newsId"};
        GV.DataBind();
    }
    /// <summary>
    /// 删除数据
    /// <remark>2010-10-23 河北大学信管团队-水亚亚 </remark>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string sql = "delete from News_Info where newsId=@newsId";
        SqlParameter[] paras = new SqlParameter[]{
          new SqlParameter("@newsId",GV.DataKeys[e.RowIndex][0].ToString())
        };
        if (DataAccess.GetCount(sql, paras) > 0)
        {//如果删除成功
            lblMessage.Text = "删除数据成功";
            //重新绑定数据
            bind();
        }
        else
        {//如果删除失败
            lblMessage.Text = "删除数据失败";
        }
    }
    /// <summary>
    /// 分页
    /// <remark>2010-10-23 河北大学信管团队-水亚亚 </remark>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GV_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GV.PageIndex = e.NewPageIndex;
        bind();
    }
    /// <summary>
    /// 添加行鼠标滑过背景
    /// <remark>2010-10-23 河北大学信管团队-水亚亚 </remark>
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GV_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //为数据行增加鼠标移动到行特性
            e.Row.Attributes.Add("onmouseover", "c=style.backgroundColor;this.style.backgroundColor='#6699ff'");
            //为数据行增加鼠标离开行特性
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
    }
}